Ext.define('xyc.view.Place3List', {
    extend: 'Ext.Panel',
    xtype: 'place3list',
    requires: [
        'xyc.model.Plant','xyc.view.PlacePlant'
    ],
    config: {
        layout: 'card',
        groupByDay: true,
        loadingText: '加载中...'
    },
    initialize: function () {
        this.callParent();
        this.searchstore = new Ext.data.Store({
            model: 'xyc.model.Plant',
            autoLoad: false,
            sorters: '',
            proxy: {
                type: 'ajax',
                url:server+ '/ext/com.cinsea.mobile.ext.XycAction?action=getplace3list',
                reader: {
                    type: 'json',
                    totalProperty: 'totalCount',
                    rootProperty: 'result'
                }

            }
        })
        this.list = new Ext.List({
            itemTpl: '<span class="name">{title}-{code}({type1}:{type2})</span> ',
            loadingText: false,
            plugins: [
                {
                    xclass: 'Ext.plugin.PullRefresh',
                    pullRefreshText: '下拉刷新...',
                    releaseRefreshText: '释放停止...',
                    loadingText: '加载中...',
                    snappingAnimationDuration: 10
                }
            ],
            store: this.searchstore
        });


        this.list.on('itemtap', this.onSelect, this);
        this.listpanel = new Ext.Panel({
            items: this.list,
            layout: 'fit'
        });


        this.listpanel.add({
            xtype: 'toolbar',
            docked: 'top',
            layout: { pack: 'left' },
            items: [
                {
                    ui: 'back',
                    text: '返回',
                    scope: this,
                    handler: function () {
                        this.getParent().setActiveItem(this.prevCard, {
                            type: 'slide',
                            reverse: true,
                            scope: this,
                            after: function () {
                                this.destroy();
                            }
                        });
                    }
                }
            ]
        });

        // Take off the spinner
        //this.list.el.unmask();

        this.add(this.listpanel);

    },

    onSelect: function (v, i) {
        record = this.searchstore.getAt(i);
        if (record !== undefined) {
            url = server+"/mobile/process.do";
            Ext.Ajax.request({
                scope: this,
                url: url + "?action=getformdata&processid=" + record.data.plantid,
                success: function (res) {
                    obj = Ext.decode(res.responseText);
                        var sessionCard = new xyc.view.PlacePlant({
                        });
                        sessionCard.addform(record.data.amount);
                        sessionCard.renderform(obj);
                        sessionCard.setPrevcard(this.listpanel);
                        sessionCard.setProcessid(record.data.processid,record.data.plantid,record.data.type1,record.data.title+'-'+record.data.code+' '+record.data.type2);

                    this.setActiveItem(sessionCard, 'slide');

                }
            });

        }

    },
    setProcessid: function (processid,title) {
            this.processid = processid;
            this.listpanel.down('toolbar').setTitle('<font size= 2>'+title+'</font>');
            this.searchstore.getProxy().setExtraParam('pid', processid);
            this.searchstore.load();
        },
    setPrevcard: function (prevc) {
        this.prevCard = prevc;
    }

});
